//
//  TemplateFoundDetailsDHWBTableViewCell.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/7/18.
//

#import "TemplateFoundDetailsDHWBTableViewCell.h"
@interface TemplateFoundDetailsDHWBTableViewCell ()<UITextFieldDelegate>

///必填
@property (nonatomic ,strong) UILabel * forceFlag;
@property (nonatomic ,strong) UILabel * name;
@property (nonatomic ,strong) UITextField * textField;


@end
@implementation TemplateFoundDetailsDHWBTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self setupView];
    }
    return self;
}


- (void)setupView{
    
    self.backgroundColor = UIColor.clearColor;
    self.contentView.backgroundColor = UIColor.whiteColor;
    self.userInteractionEnabled = YES;
    self.contentView.userInteractionEnabled = YES;
    
    UIView * makeview = [UIView new];
    makeview.backgroundColor = KcolorHex(@"#F6F7F9");
    [DTKTool YJ:kwt(5) andView:makeview];
    [self.contentView addSubview:makeview];
    [makeview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);
        make.bottom.right.offset(kwt(-10));
        make.left.offset(kwt(10));
    }];
    
    UILabel * forceFlag= [DTKTool labelWithText:@"*" andFont:kCFont(18) andTextColor:KcolorHex(@"#FA0F0F")];
    [makeview addSubview:forceFlag];
    self.forceFlag = forceFlag;
    forceFlag.mas_KLS().mas_KYS();
    [forceFlag mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(12));
        make.centerY.offset(0);
    }];
    
    
    UILabel * name = [DTKTool labelWithText:@"--" andFont:kCFont(18) andTextColor:KcolorHex(@"#222222")];
    [makeview addSubview:name];
    self.name = name;
    name.textAlignment = NSTextAlignmentLeft;
    name.mas_KLS().mas_KYS();
    [name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(forceFlag.mas_right);
        make.centerY.offset(0);
    }];
    
    
    UITextField * textField = [UITextField new];
    textField.textAlignment = NSTextAlignmentRight;
    textField.attributedPlaceholder = [DTKTool AttributedStringWithStr:@"请填写" andNodeColor:KcolorHex(@"#787A79") andSeledColor:KcolorHex(@"#787A79") andFont:kFont(17) andPattenr:@""];
    textField.font = kFont(17);
    self.textField = textField;
    textField.delegate = self;
    textField.textColor = KcolorHex(@"#222222");
    [makeview addSubview:textField];
    [textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(name.mas_right).offset(kwt(5));
        make.right.offset(kwt(-10));
        make.centerY.offset(0);
    }];
    [textField addTarget:self action:@selector(textFieldDidChangeValue:)  forControlEvents:UIControlEventEditingChanged];
}

- (void)textFieldDidChangeValue:(UITextField *)sender{
    self.model.content = sender.text;
}
- (void)setModel:(TemplateFoundDetailsTaskItemModelListModel *)model{
    _model = model;
    ///forceFlag 是否必填
    self.forceFlag.text = (model.forceFlag == 1)? @"*":@"";
    
    self.name.text = model.name;
    
    self.textField.text = model.content;
    
}
@end
